package jmine.tec.subscription.ping;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

import jmine.tec.subscription.SubscriptionSettings;
import jmine.tec.subscription.impl.AbstractPublisher;
import jmine.tec.utils.debug.impl.DebugRuntimeFactory;

/**
 * {@link AbstractPublisher} para
 * 
 * @author takeshi
 */
public class PingPublisher extends AbstractPublisher<Ping> {

    private final AtomicLong counter = new AtomicLong();

    /**
     * C'tor
     */
    public PingPublisher() {
        super(Ping.class);
        DebugRuntimeFactory.getInstance().exposeAsJMX("pingPublisher", this);
    }

    /**
     * {@inheritDoc}
     */
    public String identification() {
        return "ping";
    }

    /**
     * {@inheritDoc}
     */
    public Ping newPublication(SubscriptionSettings settings) {
        return new Ping(this.counter.getAndIncrement());
    }

    /**
     * {@inheritDoc}
     */
    public Map<String, Class<?>> subscriptionSettingsParameters() {
        return new HashMap<String, Class<?>>();
    }

    /**
     * Cria um novo {@link Ping}
     */
    public void pingNew() {
        SubscriptionSettings settings = this.newSubscriptionSettings(new HashMap<String, Object>());
        Ping p = this.newPublication(settings);
        this.publish(settings, p);
    }

}
